﻿<!DOCTYPE>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>热表工步排产下发回收页面</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
</head>
<body>
    <div id="mainSec" style="margin: 0px 1px 0px 0px">
        <div class="panelSection">
            <div class="easyui-panel " title="查询区域" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <form id="queryForm" action="">
                <div style="margin: 3px 0px 3px 3px">
                    <div style="float: left">
                        <div class="divLabel" style="margin-bottom: 5px">
                            订单号：</div>
                        <input id="txtMfgOrderName" name="MfgOrderName" class="easyui-textbox" style="width: 120px;
                            height: 20px" />
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <div class="divLabel" style="margin-bottom: 5px">
                            件号：</div>
                        <input id="txtProductName" name="ProductName" class="easyui-textbox" style="width: 120px;
                            height: 20px" />
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <div class="divLabel" style="margin-bottom: 5px">
                            批次号：</div>
                        <input id="txtContainerName" name="ContainerName" class="easyui-textbox" style="width: 120px;
                            height: 20px" />
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <div class="divLabel" style="margin-bottom: 5px">
                            排产开始时间：</div>
                        <input id="txtPlanStartTime1" name="PlanStartTime1" class="easyui-datebox" style="width: 120px;
                            height: 20px" data-options="editable:false" />
                        -
                        <input id="txtPlanStartTime2" name="PlanStartTime2" class="easyui-datebox" style="width: 120px;
                            height: 20px" data-options="editable:false" />
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <div class="divLabel" style="margin-bottom: 5px">
                            排产结束时间：</div>
                        <input id="txtPlanEndTime1" name="PlanEndTime1" class="easyui-datebox" style="width: 120px;
                            height: 20px" data-options="editable:false" />
                        -
                        <input id="txtPlanEndTime2" name="PlanEndTime2" class="easyui-datebox" style="width: 120px;
                            height: 20px" data-options="editable:false" />
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <div class="divLabel" style="margin-bottom: 5px">
                            下发状态：</div>
                        <select style='width: 80px; height: 20px' id='selStatus' name="Status" data-options='editable:false,panelHeight:100'
                            class='easyui-combobox'>
                            <option value="0">未下发</option>
                            <option value="1">已下发</option>
                        </select>
                    </div>
                    <div style="float: left; margin-left: 10px">
                        <button id="btnSearch" class="easyui-linkbutton" type="button" data-options="" style="margin-top: 16px;
                            width: 80px;">
                            查询</button>
                        <button id="btnReset" class="easyui-linkbutton" type="button" data-options="" style="margin-top: 16px;
                            width: 50px;">
                            重置</button>
                    </div>
                    <div style="clear: both">
                    </div>
                </div>
                </form>
            </div>
        </div>
        <div class="panelSection">
            <div class="easyui-panel " title="查询结果" style="padding: 3px; width: 100%" data-options="closable:false,collapsible:true,minimizable:false,maximizable:false">
                <div id="gdBtn">
                    <div id="divSend" style="float: left">
                        <button id="btnSend" class="easyui-linkbutton" type="button" style="width: 100px;
                            height: 26px">
                            下发派工</button>
                    </div>
                    <div id="divReCall" style="float: left">
                        <button id="btnReCall" class="easyui-linkbutton" type="button" style="width: 100px;
                            height: 26px">
                            收回</button>
                    </div>
                    <div id="div1" style="float: left; margin-left: 20px">
                        <button id="btnReSendDC" class="easyui-linkbutton" type="button" style="width: 150px;
                            height: 26px">
                            工控网数据重复推送</button>
                    </div>
                    <div id="div2" style="float: left; margin-left: 20px">
                        <button id="btnExport" class="easyui-linkbutton" type="button" style="width: 100px;
                            height: 26px">
                            导出</button>
                    </div>
                </div>
                <div id="dvApsPlanInfo" class="dvgrid-cellwarp" style="background: #fff; margin: 3px 0px 3px 0px">
                    <div style="width: 99%">
                        <table id="gdApsPlanInfo" class="easyui-datagrid" style="width: 100%; height: 500px;"
                            data-options="fitColumns:true,rownumbers:true">
                        </table>
                        <div id="pp" style="float: right" class="easyui-pagination" data-options="
                    layout:['first','prev','next','last','manual','info'],             
                    total: 0,
                    showPageList: false,
                    showPageInfo: false,
                    showRefresh: false,
                    afterPageText:'共&nbsp{pages}&nbsp页',
                    buttons:[{
                            iconCls:'',
                            text:'Go',
                            group:'paging-tail-btns',
                            id:'pageGo'
                    }]  
                ">
                        </div>
                    </div>
                    <div style="clear: both">
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/datagrid-detailview.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    /*
    创建人：zhangrj
    日期：2024-08-13
    描述：工步排产下发JS
    */
    var page = {
        pageTotal: 0,
        pageSize: 20,
        pageNumber: 1,
        rootPath: getRootPath(), //网站根路径
        url: getRootPath() + "/Ashx/ApsHandler/RbApsPlanDownSendHandler.ashx",
        commonUrl: getRootPath() + "/Ashx/CommonHandler.ashx",
        //初始化页面
        init: function () {
            page.bind();
            customizedEasyuiPagination('pp'); //定制化分页
            $("#selStatus").combobox('setValue', '0'); //默认选中未下发
            $("#divReCall").hide();
        },
        //页面事件绑定
        bind: function () {
            //列表加载
            $("#gdApsPlanInfo").datagrid({
                //                toolbar: "#gdBtn",
                onLoadSuccess: function (data) {
                    $('#pp').pagination('refresh', {	// 改变选项，并刷新分页栏信息
                        total: page.pageTotal,
                        pageSize: page.pageSize,
                        pageNumber: page.pageNumber
                    });
                    customizedEasyuiPagination('pp'); //定制化分页
                },
                columns: [[
          { field: 'ck', title: '选择', checkbox: true },
          { field: 'MFGORDERNAME', title: '订单号', width: 120 },
          { field: 'CONTAINERNAME', title: '批次号', width: 200, styler: function (value, row, index) {
              if (row.SHIPENDTIME != null && dayjs(dayjs(row.SHIPENDTIME).format('YYYY-MM-DD')) < dayjs(dayjs(row.ENDTIME).format('YYYY-MM-DD'))) {
                  return 'background-color:#ffee00;';
              }
          }
          },
          { field: 'WORKFLOWINFO', title: '排产工艺信息', width: 200 },
          { field: 'FACONTAINERNAME', title: '主制批次', width: 200 },
          { field: 'WORKFLOWSTEPNAME', title: '在制工序', width: 120 },
          { field: 'QTY', title: '在制数', width: 80 },
          {
              field: 'STARTTIME', title: '计划开始时间', width: 150, formatter: function (value, row, index) {
                  if (!isNullOrWhiteSpaceStr(value)) {
                      return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
                  }
              }
          },
          {
              field: 'ENDTIME', title: '计划结束时间', width: 150, formatter: function (value, row, index) {
                  if (!isNullOrWhiteSpaceStr(value)) {
                      return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
                  }
              }
          },
          {
              field: 'SHIPSTARTTIME', title: '转工计划开始时间', width: 150, formatter: function (value, row, index) {
                  if (!isNullOrWhiteSpaceStr(value)) {
                      return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
                  }
              }
          },
          {
              field: 'SHIPENDTIME', title: '转工计划结束时间', width: 150, formatter: function (value, row, index) {
                  if (!isNullOrWhiteSpaceStr(value)) {
                      return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
                  }
              }
          }
        ]],
                view: detailview,
                detailFormatter: function (index, row) {
                    return '<div style="padding:2px;position:relative;"><table class="ddv"></table></div>';
                },
                onExpandRow: function (index, row) {
                    var ddv = $(this).datagrid('getRowDetail', index).find('table.ddv');
                    ddv.datagrid({
                        url: page.url + "?action=GetApsPlanDetailList&apsID=" + row.APSPLANINFOID + "&status=" + $("#selStatus").combobox('getValue'),
                        fitColumns: true,
                        singleSelect: false,
                        rownumbers: true,
                        height: 'auto',
                        columns: [[
              { field: 'ck', title: '选择', checkbox: true },
              { field: 'STEPINFONO', title: '工步号', width: 80 },
              { field: 'STEPINFODESC', title: '工步名', width: 100 },
              { field: 'RESOURCEDESC', title: '设备名', width: 100 },
              { field: 'WORKCENTERNAME', title: '工区', width: 100 },
              { field: 'TEAMNAME', title: '班组', width: 100 },
              {
                  field: 'STARTTIME', title: '计划开始时间', width: 150, formatter: function (value, row, index) {
                      if (!isNullOrWhiteSpaceStr(value)) {
                          return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
                      }
                  }
              },
              {
                  field: 'ENDTIME', title: '计划结束时间', width: 150, formatter: function (value, row, index) {
                      if (!isNullOrWhiteSpaceStr(value)) {
                          return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
                      }
                  }
              },
              {
                  field: 'RESSTARTTIME', title: '设备开始时间', width: 150, formatter: function (value, row, index) {
                      if (!isNullOrWhiteSpaceStr(value)) {
                          return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
                      }
                  }
              },
              {
                  field: 'RESENDTIME', title: '设备结束时间', width: 150, formatter: function (value, row, index) {
                      if (!isNullOrWhiteSpaceStr(value)) {
                          return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
                      }
                  }
              },
              {
                  field: 'DISDATE', title: '派工时间', width: 150, formatter: function (value, row, index) {
                      if (!isNullOrWhiteSpaceStr(value)) {
                          return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
                      }
                  }
              },
              {
                  field: 'RECORDTIME', title: '生成记录时间', width: 150, formatter: function (value, row, index) {
                      if (!isNullOrWhiteSpaceStr(value)) {
                          return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
                      }
                  }
              },
              {
                  field: 'SENDTIME', title: '推送数据中心时间', width: 150, formatter: function (value, row, index) {
                      if (!isNullOrWhiteSpaceStr(value)) {
                          return dayjs(value).format('YYYY-MM-DD HH:mm:ss');
                      }
                  }
              },
              { field: 'BUSINESSID', title: '数据中心ID', width: 150 }
            ]],
                        onResize: function () {
                            $('#gdApsPlanInfo').datagrid('fixDetailRowHeight', index);
                        },
                        onLoadSuccess: function () {
                            setTimeout(function () {
                                $('#gdApsPlanInfo').datagrid('fixDetailRowHeight', index);
                            }, 0);
                            $(this).datagrid('checkAll');
                        }
                    });
                    $('#gdApsPlanInfo').datagrid('fixDetailRowHeight', index);
                }
            });
            $("#selStatus").combobox({
                onChange: function (value) {
                    switch (value) {
                        case "0":
                            $("#divSend").show();
                            $("#divReCall").hide();
                            break;
                        case "1":
                            $("#divSend").hide();
                            $("#divReCall").show();
                            break;
                        default:
                            $("#divSend").hide();
                            $("#divReCall").hide();
                            break;
                    }
                    page.clearPage(false, true);
                }
            });
            //查询按钮
            $('#btnSearch').on("click", function () {
                page.clearPage(false, true);
                page.pageNumber = 1;
                page.searchData();
            });
            //下发按钮
            $('#btnSend').on("click", function () {
                page.sendToDis();
            });
            //回收按钮
            $('#btnReCall').on("click", function () {
                page.reCall();
            });
            //同步执行按钮
            $('#btnReSendDC').on("click", function () {
                $.messager.confirm('确认', '工控网数据重复，是否再次推送？', function (r) {
                    if (r) {
                        page.reSendDC();
                    }
                });
            });
            //导出数据
            $('#btnExport').on("click", function () {
                var params = {};
                var queryFormData = $("#queryForm").serializeArray();
                $.each(queryFormData, function () {
                    params[this.name] = this.value;
                });
                FileDownLoad(page.url, { action: "ExportApsPlanData", params: JSON.stringify(params) });
            });
            //分页事件
            $('#pp').pagination({
                onSelectPage: function (pageNumber, pageSize) {
                    //                customizedEasyuiPagination('pp'); //定制化分页
                    page.pageSize = pageSize; page.pageNumber = pageNumber === 0 ? 1 : pageNumber;
                    page.searchData();
                }
            });
            //绑定分页go按钮
            $('#pageGo').on("click", function () {
                var pageNumber = Number($(this).parents('tr').find('.pagination-num').val());
                page.pageSize = $(".pagination-page-list").val();
                page.pageNumber = pageNumber;
                page.searchData();
            });
            //清除按钮
            $('#btnReset').on("click", function () {
                page.clearPage(true, true);
                page.pageNumber = 1; page.pageTotal = 0
                $('#pp').pagination('refresh', {
                    total: page.pageTotal,
                    pageSize: page.pageSize,
                    pageNumber: page.pageNumber
                });
            });
        },
        //查询
        searchData: function () {
            var params = {
                pageSize: page.pageSize,
                pageIndex: page.pageNumber
            };
            var queryFormData = $("#queryForm").serializeArray();
            $.each(queryFormData, function () {
                params[this.name] = this.value;
            });
            page.post(page.url, { action: "GetApsPlanListByPage", params: JSON.stringify(params) }, true, function (res) {
                if (!res.Result) {
                    displayMessage(res.Message, res.Result);
                    return;
                }
                page.pageTotal = res.RowCount;
                $("#gdApsPlanInfo").datagrid('loadData', { total: res.RowCount, rows: res.DBTable });
            });
        },
        //下发派工
        sendToDis: function () {
            var selectRows = $("#gdApsPlanInfo").datagrid('getChecked');
            if (selectRows.length === 0) {
                displayMessage("请选择批次", false);
                return;
            }
            //            var datas = selectRows.map(function (item) {
            //                return {
            //                    containerId: item.CONTAINERID,
            //                    containerName:item.CONTAINERNAME,
            //                    qty:item.QTY
            //                }
            //            });
            page.post(page.url, { action: "SaveApsPlanSendToDis", params: JSON.stringify(selectRows) }, true, function (res) {
                if (res.Result) {
                    page.searchData();
                }
                displayMessage(res.Message, res.Result);
            });
        },
        //回收
        reCall: function () {
            var selectRows = $("#gdApsPlanInfo").datagrid('getChecked');
            if (selectRows.length === 0) {
                displayMessage("请选择批次", false);
                return;
            }
            var datas = selectRows.map(function (item) {
                return {
                    containerId: item.CONTAINERID,
                    containerName: item.CONTAINERNAME
                }
            });
            page.post(page.url, { action: "SaveApsPlanRecall", params: JSON.stringify(datas) }, true, function (res) {
                if (res.Result) {
                    page.searchData();
                }
                displayMessage(res.Message, res.Result);
            });
        },
        //同步执行
        reSendDC: function () {
            var selectRows = $("#gdApsPlanInfo").datagrid('getChecked');
            if (selectRows.length === 0) {
                displayMessage("请选择批次", false);
                return;
            }
            var datas = selectRows.map(function (item) {
                return {
                    containerId: item.CONTAINERID,
                    containerName: item.CONTAINERNAME
                }
            });
            page.post(page.url, { action: "ReSendDispatchToDC", params: JSON.stringify(datas) }, true, function (res) {
                displayMessage(res.Message, res.Result);
            });
        },
        //禁用页面按钮
        disableBtn: function () {
            $("#mainSec").find(".easyui-linkbutton").each(function () {
                $(this).linkbutton('disable');
            });
        },
        //启用页面按钮
        enableBtn: function () {
            $("#mainSec").find(".easyui-linkbutton").each(function () {
                $(this).linkbutton('enable');
            });
        },
        //清除页面（查询区域，列表区域）
        clearPage: function (query, list) {
            if (query) {
                $("#txtMfgOrderName").textbox("clear"); //订单号
                $("#txtContainerName").textbox("clear"); //批次号
                $("#txtProductName").textbox("clear"); //件号
                $("#txtPlanStartTime1").datebox("clear"); //排产开始时间
                $("#txtPlanStartTime2").datebox("clear"); //排产开始时间
                $("#txtPlanEndTime1").datebox("clear"); //排产结束时间
                $("#txtPlanEndTime2").datebox("clear"); //排产结束时间
                $("#selStatus").combobox("setValue", "0"); //未下发状态
            }
            if (list) {
                clearEasyuiDataGrid("gdApsPlanInfo"); //清空列表
            }
        },
        //post数据（路径，参数，是否异步，成功返回方法）
        post: function (url, param, async, callback) {
            $.ajax({
                type: "Post",
                url: url,
                data: param,
                cashe: false,
                async: async,
                dataType: "json",
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    callback(data);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    displayMessage(XMLHttpRequest.responseText, false);
                    $("body").find(".easyui-linkbutton").each(function () {
                        $(this).linkbutton('enable');
                    });
                }
            });
        }
    };
    $(function () {
        page.init();
    });
</script>
